﻿using System;

namespace NQueries.Sample
{
    public static class SampleNonGenericQueries
    {
        /// <summary>
        /// Non generic read by id uses a non generic repository to get an entity by its id.
        /// Typicall use case would be retrival of an unknown object in a mvc model binder.
        /// </summary>
        /// <returns></returns>
        public static void ReadById()
        {
            Test.CreateDatabase();
            Test.CreateCustomer("Read");

            int id = SampleSimpleOperations.Read().Id;

            using (IUnitOfWork unitOfWork = UnitOfWork.Begin("ReadById"))
            {
                object customer = unitOfWork.DataContext.GetById(typeof(Customer), id);
                if (customer == null)
                    throw new ArgumentNullException();
            }
        }
    }
}